<?php
require_once ("../utils/ConnectionFactory.php");
require_once ("../persistance/data/ClientDO.php");

/**
 */
class ClientDAO {
	
	/**
	 * Retourne un ClientDO, correspondant a un Client
	 *
	 * @param String $login_Client        	
	 * @return NULL ClientDO
	 */
	public function getClientDO($login_client) {
		$connection = ConnectionFactory::getConnection ();
		$reponse = mysql_query ( "SELECT * FROM client WHERE login_client LIKE '" . $login_client . "'" );
		if ($reponse == null) {
			return null;
		}
		while ( $data = mysql_fetch_assoc ( $reponse ) ){
			$ClientDO = $this->setClientDO ( $data );
		}
		return $ClientDO;
	}

	public function getListClientDO() {
		$connection = ConnectionFactory::getConnection ();
		$reponse = mysql_query ( "SELECT * FROM client where connecte = 1");
	
		if ($reponse == null) {
			return null;
		}
	
		$listClientDO = new ArrayObject ();
		while ( $data = mysql_fetch_assoc ( $reponse ) ){
			$clientDO = $this->setClientDO ( $data );
			$listClientDO->append ( $clientDO );
		}
		return $listClientDO;
	}
	
	private function setClientDO($donnee) {
		$ClientDO = new ClientDO ();
		$ClientDO->setNumClient ( $donnee ['num_client'] );
		$ClientDO->setLoginClient ( $donnee ['login_client'] );
		$ClientDO->setNomClient ( $donnee ['nom_client'] );
		$ClientDO->setPrenomClient ( $donnee ['prenom_client'] );
		$ClientDO->setEmailClient ( $donnee ['email_client'] );
		$ClientDO->setTelClient ( $donnee ['tel_client'] );
		$ClientDO->setTypeClient( $donnee ['type_client'] );
		$ClientDO->setDateInscription( $donnee ['date_inscription'] );
		$ClientDO->setNbVisites( $donnee ['nb_visites_mois'] );
		$ClientDO->setConnecte( $donnee ['connecte'] );
		
		return $ClientDO;
	}
}
